import smtplib
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart


def my_email(msg):
    host = 'smtp.qq.com'
    port = 465
    user = 'xueguopeng@foxmail.com'
    password = 'islclqzazvnidbdc'
    subject = '脚本运行结束通知'

    email_client = smtplib.SMTP_SSL(host=host)
    # 设置发件人邮箱的域名和端口
    email_client.connect(host=host, port=port)

    # 登陆邮件，权限验证，password为邮箱密码
    result = email_client.login(user=user, password=password)
    print("登录结果", result)

    # 发送邮件，from_addr：发送人，to_addrs：收件人 ，msg：发送的文本
    message = MIMEMultipart()
    message['From'] = user
    message['To'] = user
    message['Subject'] = subject
    message.attach(MIMEText(msg))
    email_client.sendmail(from_addr=user, to_addrs=user, msg=message.as_string())
    # 关闭邮件客户端
    email_client.close()


if __name__ == '__main__':
    my_email(__file__)